This is Yet Another Midi Synced LFO! Hurray!

It's in the middle of the night, but I have to post it because I feel like a
bloody genious. :-)
I was thinking that there HAD to be a way to have some kind of feedback
system, where the output was checked if it was the right frequency and the
error was put back into the system. So I thought about it and came up with
this, in my opinion brilliant, solution. (Humble as ever).

MidiSyncFeedbackWorks.pch
It works like this: I use an LFO (called the "CompareLFO"). It uses a very
slow sawtooth that is reset by the clock you wish to sync with. So in
effect, it outputs a controlsignal with a linear decline.
I'm using the inverted sync signal to get a sync halfway between the
clockpulses, and use this "halfway sync" to sample the output from the LFO
with a S&H. As you now realize, the output from the CompareLFO at the
halfway time will reflect the error in frequency between the clock signal
and the CompareLFO, being a positive number if the CompareLFO is slower, and
a negative number if it is faster, the number being larger if the error is
larger.
This error control signal is fed back into the LFO, the LFO therefore going
faster is it is too slow, and slower if it is too fast. At the next halfway
clockpulse, a new sample is taken, added to the old value (with the
ControlMixer1) and again fed back into the LFO. Most likely, the LFO will
this time be too fast, and the sample will be taken when the CompareLFO
output is negative. But the error will be smaller, and thus, in a couple of
iterations, the CompareLFO will soon set at the correct frequency.

To get the waveform I want (the CompareLFO has to have a sawtooth form) I
just slave another LFO to the CompareLFO. Done!!

Drawbacks:
- It's not 100% stable. It does wobble a bit. It's noticeable, but not
annoying. That could probably be fixed by having a portamento inbetween the
S&H and the LFO, with a time setting of a couple of clocks. I haven't tried
it though.
- It can't take arbitrary frequencies without tweaking. As it is set up now,
it works fine with everything from 60 to 180bpm, so it has a wide range, but
I'm now syncing to every 24th midi clock. What you probably want to to is to
sync to every (or every third) midi clock, and then use the OutputLFO rate
setting to divide that into the speed you want.
- If you suddenly slow down the tempo to less than half, it may fuck up.
Tempo changes can be rather fast, but not abrupt. More that a 50% change per
tick may not work.
- It can only work on sync signals with 50% pulsewidth. If you sync signals
that are just ticks or peaks, you need to put it through a divider first.

Benefits:
- Only uses 4.3%
- You can get an arbitrary LFO waveform, even sinus.
- Doens't rely on hardsyncing of the OutputLFO, but it can use it without
problem if exact starts are wanted.

Well, thats about it. Questions, improvements and critique welcome. Even
more welcome is unashamed worship of my superiour intellect. :-)

I alsow, for good measure, throw in two patches I made today which I like.
The "HeavenlyOrgan.pch" and "Terra-nonfirmawobbleplonk.pch". :-)

I also throw in my most useful patch: "Test tones.pch". It starts out as
default with a A (440Hz) tuning tone. It also has loads of otehr test tones.
I used my Modular instead of a test tone generator when I trimmed in my
reel-to-reel multitrack. Verrry handy. Yeah, I know, it's a trivial patch,
anybody could do it. It's just a way to point to another use of the modular:
Test instrument. :-)


